package com.wh.base.sys.user.controller.form;

import java.util.ArrayList;
import java.util.List;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

@Data
@ApiOperation(value = "插入表单类")
public class InsertForm {
	
	@NotNull(message = "用户名不能为空")
	@Schema(description = "用户名")
    private String username;
	
	@NotNull(message = "真实姓名不能为空")
	@Pattern(regexp = "^[\\u4e00-\\u9fa5]{2,10}$", message = "真实姓名内容不正确")
	@Schema(description = "真实姓名")
    private String realName;
	
	@NotBlank(message = "手机号不能为空")
    @Pattern(regexp = "^1\\d{10}$", message = "手机号内容不正确")
    @Schema(description = "手机号")
    private String phone;
	
	@Email(message = "email内容不正确")
    @Schema(description = "邮箱")
    private String email;

	@NotBlank(message = "密码不能为空")
	@Size(min=6, max=100, message = "密码不能小于6位字符,大于100个字符")
    @Schema(description = "密码")
    private String password;
	
	@Pattern(regexp = "^(\\d+,?)+$", message = "角色id格式错误")
	@Schema(description = "roleIds,多个id使用逗号分割")
	private String roleIds;
	
	public List<Long> roleIdList(){
		String[] idArr = roleIds.split(",");
		List<Long> roleIdList = new ArrayList<>();
		for(String id : idArr) {
			roleIdList.add(Long.parseLong(id));
		}
		return roleIdList;
	}
}
